<template>
    <section class="modlude">
      <el-table :data="formData" style="width: 100%" stripe @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="55"></el-table-column>
        <!-- <el-table-column prop="id" label="id" width="100"></el-table-column> -->
      <el-table-column prop="deviceGuid" label="设备标识" align="center"></el-table-column>
        <el-table-column prop="devName" label="设备名称" align="center"></el-table-column>
        <el-table-column prop="" label="设备状态" align="center">
          <template slot-scope="scope">
                {{scope.row.status=='NORMAL' ?'正常':"删除"}}
          </template>
        </el-table-column>
        <el-table-column prop="type" label="出入口类型" align="center"></el-table-column>
        <el-table-column prop="" label="创建时间" width=150 align="center">
                <template slot-scope="scope" v-if="scope.row.gmtCreate">
                    {{ formatDate(scope.row.gmtCreate) }}
                </template>
        </el-table-column>
      </el-table>
      <paging @changePage = handleCurrentPage :get-total='total' :moduleInfor="moduleInfor"></paging>
    </section>
  </template>
  
  <script>
  import paging from '../../components/paging.vue';
  import {
    getCarDevLogList
  } from '../../url/api';
  export default {
    data(){
      return{
        checkStrictly:false,
        bindRole:{},
        showmenuList:[],
        menuList:[],
        option1:[],
        xqTree:[],
        isAddorUpdate:1,//1添加、2修改
        formSearch:{
          current:1,
          size:10
        },
        formData: [],//数据
        deleBatch: [],//删除数据
        formUpdate:{},//修改表单
        total: 0,//数据总数
        pages:0,//页面总数
        addDialog:false,
        updateDialog:false,
        dialog:false,
        replyType:1,//1。单个回复 2.批量回复
        formPush:{
        },
        dataTree:[],
        defaultProps: {//树状图key定义
          children: 'data',
          label: 'name'
        },
        defaultProps2: {
          children: 'children',
          label: 'name',
          value: 'id',
          expandTrigger: 'hover',checkStrictly: true
        },
        reply:'',
        moduleInfor:{},
        rules: {
          name:[{ required: true, message: '该项不能为空'}],
          type:[{ required: true, message: '该项不能为空',trigger: 'blur'}],
          xqId:[{ required: true, message: '该项不能为空',trigger: 'blur'}],
        },
        imageUrl:''
      }
    },
    created(){

this.Bus.$on('sendTableData5',(data)=>{
    console.log('~~~~',data);
    this.formSearch = data.formSearch;
    // this.total = data.total
    this.getList();
  })
},
 
    components: {
          paging,
      },
    methods:{
        getList(){
            getCarDevLogList(this.formSearch).then((res)=>{
                console.log(res);
                if(res.data.ok){
                   this.formData = res.data.data.records.filter((item)=>{
                return item
                })
                this.total = res.data.data.total;
            }else{
          this.$message(res.data.msg);
        }
            })
        },
        handleSelectionChange(val, self) {
              //多选
              this.deleBatch = val;
              console.log(this.deleBatch);
          },
          handleCurrentPage(val) {
              //页码改变
              this.formSearch.current = val;
              this.getList();
          },
        //时间格式拼接
        formatDate(time) {
          if (time.length < 6) {
            time.push(0); // 当时间秒为00时，后端只会返回五个数字，所以往数组末尾添加默认值 0
          }
            const [year, month, day, hour, minute, second] = time;
            const formattedDate = `${year}-${this.padZero(month)}-${this.padZero(day)}`;
            const formattedTime = `${this.padZero(hour)}:${this.padZero(minute)}:${this.padZero(second)}`;
            return `${formattedDate} ${formattedTime}`;
        },
        padZero(num) {
        return num.toString().padStart(2, '0');
        },
    },
    mounted () {
        this.getList()
    },
  };
  </script>
  <style scoped>
  .cont_box {
      width: 100%;
      display: flex;
  }
  .cont_box_left,
  .cont_box_right {
      flex: 1;
      background: transparent;
      padding: 10px;
  }
  .cont_box_left {
      margin-right: 10px;
  }
  .margin10 {
      margin-bottom: 10px;
  }
  .marginRight {
      margin-bottom: 10px;
      border-bottom: 1px solid #eee;
  }
  .cont_box_right .el-form-item {
      margin-bottom: 20px;
  }
  </style>
  